package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ) {

            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.gender,c.name,c.floor " +
                    "FROM teacher t JOIN class c  on t.id = c.teacher_id WHERE t.name='王克晶'";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                String tName = rs.getString("t.name");
                String tGender = rs.getString("t.gender");
                String cName = rs.getString("c.name");
                int floor = rs.getInt("c.floor");
                System.out.println(tName + " " + tGender + " " + cName + " " + floor);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
